class Student:
    def __init__(self, id, name, gender):
        self.id = id
        self.name = name
        self.gender = gender


student_01 = Student(1, "张三", "男")
student_02 = Student(2, "莉丝", "女")
student_03 = Student(3, "王武", "男")


class StudentManagement:
    def __init__(self):
        self.students = [student_01, student_02, student_03]

    def student_menu(self):
        while True:
            print("""
------------------欢迎来到学生管理系统------------------
1.根据学号查看学员信息
2.添加学员
3.根据学号删除学员后，查看所有学员信息
4.查询当前所有学员信息
5.退出系统
请输入操作：""", end="")
            input_num = int(input())
            if input_num == 1:
                self.show_byid()
            elif input_num == 2:
                self.add_student()
            elif input_num == 3:
                self.show_students()
                print("请输入学生id：", end="")
                student_id = int(input())
                self.delete_student(student_id)
            elif input_num == 4:
                self.show_students()
            elif input_num == 5:
                exit()

    def show_byid(self):
        print("请输入学生id：", end="")
        student_id = int(input())
        found = False
        for student in self.students:
            if student.id == student_id:
                print(f"{'学号':<10} {'姓名':<10} {'性别':<10}")
                print(f"{student.id:<10} {student.name:<10} {student.gender:<10}")
                found = True
        if not found:
            print("学生id不存在")

    def delete_student(self, student_id):
        for student in self.students:
            if student.id == student_id:
                self.students.remove(student)
                return True  # 删除成功
        else:
            print("你想删除的学生不存在！")
        return False  # 删除失败

    def add_student(self):
        print("请输入学生id：", end="")
        try:
            id = int(input())
        except ValueError:
            print("输入有误")
            return self.add_student()
        print("请输入学生姓名：", end="")
        name = input()
        print("请输入学生性别：", end="")
        gender = input()
        if gender != "男" and gender != "女":
            print("性别输入错误")
            return self.add_student()
        student = Student(id, name, gender)
        self.students.append(student)

    def show_students(self):
        print(f"{'学号':<10} {'姓名':<10} {'性别':<10}")
        for student in self.students:
            print(f"{student.id:<10} {student.name:<10} {student.gender:<10}")


if __name__ == "__main__":
    studentManagement = StudentManagement()
    studentManagement.student_menu()
